import requests
import ddddocr

# 登录的地址
url = 'https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'

# 验证码图片地址
yzm_url = 'https://so.gushiwen.cn/RandCode.ashx'
# 发起网络请求
res = requests.get(yzm_url)
with open('yzm.jpg', 'wb') as f:
    f.write(res.content)

# 对ddddocr进行实例化
ocr = ddddocr.DdddOcr()
# 读取验证码图片
with open('yzm.jpg', 'rb')as f:
    # 读取图片信息
    img_bytes = f.read()
# 识别验证码
res = ocr.classification(img_bytes)
print('识别后的验证码为：', res)

# 用户名和密码
email = '793390457@qq.com'
pwd = "xlg17346570232"
# 表单数据
data = {
        "__VIEWSTATE": "1FClS0KnSNVXOhY/k04JfwQB/bmEmb09u9DuGPwln527V7RWbOfsk027f5NQuTFCY8MLC1ru7SkJ42sDWYxePaAzbrNUWfElMQ+8Qc32NkrtGEy6O2f6KXCGGgHdic1XUXkCfd8GHPlWhLajW3sykYCeCsU=",
        "__VIEWSTATEGENERATOR": "C93BE1AE",
        "from": "http://so.gushiwen.cn/user/collect.aspx",
        "email": email,
        "pwd": pwd,
        "code": res,
        "denglu": "登录"
}
# 请求头
headers = {
    'Content-Type':'application/x-www-form-urlencoded',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
    'Referer':'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
}
res = requests.post(url, headers=headers, data=data)
print(res.content.decode())